﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JewelCaseWriter;
using MusicRipperDataAccess;

namespace UWSP_Music_Ripper
{
   public partial class frmPrintJewelCase : Form
   {
		#region Fields (1) 

      AlbumHandler myAlbumHandler;

		#endregion Fields 

		#region Constructors (2) 

      public frmPrintJewelCase( )
      {
         InitializeComponent( );
      }

      public frmPrintJewelCase(AlbumHandler inAH ):this()
      {
         this.myAlbumHandler = inAH;
         LoadListBoxes( );
      }

		#endregion Constructors 

		#region Methods (5) 

		// Private Methods (5) 

      private void btnCancel_Click( object sender, EventArgs e )
      {
         this.Close( );
      }

      private void btnPrint_Click( object sender, EventArgs e )
      {
         if(this.ReadyToPrint())
         {
            Album a = this.myAlbumHandler.GetAlbum( this.lstArtist.Text, this.lstAlbum.Text );
            JewelCaseHelper.WriteTheCase( a );
         }
      }

      private void LoadListBoxes()
      {
         this.lstArtist.DataSource = myAlbumHandler.GetArtist( );  
      }

      private void lstArtist_SelectedIndexChanged( object sender, EventArgs e )
      {
         this.lstAlbum.DataSource = myAlbumHandler.GetAlbumTitleByArtist( this.lstArtist.Text );
      }

      private bool ReadyToPrint( )
      {
         
         if(this.lstArtist.SelectedItems.Count < 1)
         {
            MessageBox.Show( "Please choose an artist" );
            return false;
         }
         if(this.lstAlbum.SelectedItems.Count < 1)
         {
            MessageBox.Show( "Please choose an album" );
            return false;
         }
         return true;
        
      }

		#endregion Methods 
   }
}
